*******************************************************************************
* Specify city and years
*******************************************************************************

local city = "fort_worth"

use dataset_`city'_cross, clear
append using dataset_`city'_cross_pres
replace year = 2009 if year == 2012
replace year = 2014 if year == 2016

local y1 2009
local y2 2014
local y3 2020

*******************************************************************************
* Ref support and percent black
*******************************************************************************

foreach year in `y1' `y2' `y3' {

	local mytext
	if `year' == `y1' ///
		local mytext ///
		text(0.45 0.4 "{&larr}Dem. pres vote 2012", col(gray) ///
		size(vsmall))
	if `year' == `y2' ///
		local mytext ///
		text(0.45 0.35 "{&larr}Dem. pres vote 2016", col(gray) ///
		size(vsmall))
	if `year' == `y3' ///
		local mytext ///
		text(0.85 0.4 "Dem. pres vote 2020{&rarr}", col(gray) ///
		size(vsmall))
		
	#delimit;
	
	gr tw
		(sc pctyes pctnhblack if year == `year' [aw=totalvotes], 
			msym(Oh) msize(tiny) col(gray))
		(lpoly pctdem pctnhblack if year == `year' [aw=totalvotes], 
			col(gray) lwid(thin))
		(lpoly pctyes pctnhblack if year == `year' [aw=totalvotes], 
			lcol(black) lwid(thick))
		,
			legend(off)
			plotregion(style(none))
			ylab(, angle(horiz))
			name(g`year', replace)
			title(`year')
			xtitle("")
			ytitle("")
			yline(0.5, lpat(dash))
			`mytext'
			;
			
	#delimit cr
	
	gr close
	
}

gr combine g`y1' g`y2' g`y3', rows(1) xsize(3) ysize(1) ycommon xcommon ///
	b1title("Share Black") ///
	l1title("Share Yes Vote") ///
	imargin(zero) name(a, replace) ///
	title("(a) Police budget support and share black by year.")

gr close

*******************************************************************************
* Ref support and miles from shooting
*******************************************************************************

foreach year in `y1' `y2' `y3' {
	
	#delimit;
	
	gr tw
		(sc pctyes distance if year == `year' [aw=totalvotes], 
			msym(Oh) msize(tiny) col(gray))
		(lpoly pctdem distance if year == `year' [aw=totalvotes], 
			col(gray) lwid(thin))
		(lpoly pctyes distance if year == `year' [aw=totalvotes], 
			lcol(black) lwid(thick))
		,
			legend(off)
			plotregion(style(none))
			ylab(, angle(horiz))
			name(g`year', replace)
			title(`year')
			xtitle("")
			ytitle("")
			yline(0.5, lpat(dash))
			xscale(reverse)
			;
			
	#delimit cr
	
	gr close
	
}

local mytitle = "(b) Police budget support distance to " + ///
	"2019 killing of Atatiana Jefferson."

gr combine g`y1' g`y2' g`y3', rows(1) xsize(3) ysize(1) ycommon xcommon ///
	b1title("Distance to Shooting (Miles)") ///
	l1title("Share Yes Vote") ///
	imargin(zero) name(b, replace) ///
	title("`mytitle'")	

gr close

*******************************************************************************
* Combine
*******************************************************************************	

gr combine a b, rows(2) ysize(1.5) xsize(2)  
gr export "_output/figure 3.eps", replace

*******************************************************************************
* End
*******************************************************************************
